package org.jeecg.modules.ParameterModule.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.ParameterModule.entity.*;
import org.jeecg.modules.ParameterModule.service.CategoryInfoService;
import org.jeecg.modules.ParameterModule.service.ImportExportService;
import org.jeecg.modules.zhoupackage.pojo.MlccFabricInfo;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 参数的导入导出
 * */
@Api(tags="导出数据")
@RestController
@RequestMapping("/admin/ExportData")
@Slf4j
public class ImportExportController {
    @Autowired
    private ImportExportService exportService;

    /**
     * 导出定制下的参数
     */
    @RequestMapping(value = "/exportCategory")
    public ModelAndView exportCategory(String category_id) {
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, "定制项");
        //注解对象Class
        mv.addObject(NormalExcelConstants.CLASS, ExcelCategoryInfo.class);
        //自定义表格参数
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("定制项模板", "定制项模板文件"));
        //导出数据列表
        mv.addObject(NormalExcelConstants.DATA_LIST, exportService.ExportCategory(category_id));
        return mv;
    }

    /**
     * 导出尺寸
     */
    @RequestMapping(value = "/export_bodysizes")
    public ModelAndView export_bodysizes(String category_id,int type) {
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //type:0成衣尺寸,净体尺寸
        if(type==0){
            //导出文件名称
            mv.addObject(NormalExcelConstants.FILE_NAME, "成衣尺寸");
            //注解对象Class
            mv.addObject(NormalExcelConstants.CLASS, ExcelBodysizes.class);
            //自定义表格参数
            mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("成衣尺寸", "成衣尺寸模板文件"));
            //导出数据列表
            mv.addObject(NormalExcelConstants.DATA_LIST, exportService.Export_bodysizes(category_id,type));
        }else {
            //导出文件名称
            mv.addObject(NormalExcelConstants.FILE_NAME, "净体尺寸");
            //注解对象Class
            mv.addObject(NormalExcelConstants.CLASS, ExcelBodysizes.class);
            //自定义表格参数
            mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("净体尺寸", "净体尺寸模板文件"));
            //导出数据列表
            mv.addObject(NormalExcelConstants.DATA_LIST, exportService.Export_bodysizes(category_id,type));
        }
        return mv;
    }
    /**
     * 导出返修尺寸
     */
    @RequestMapping(value = "/export_fanxiu_bodysizes")
    public ModelAndView export_fanxiu_bodysizes(String category_id) {
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, "返修尺寸");
        //注解对象Class
        mv.addObject(NormalExcelConstants.CLASS, ExcelFanxiuBodysize.class);
        //自定义表格参数
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("返修尺寸", "返修尺寸模板文件"));
        //导出数据列表
        mv.addObject(NormalExcelConstants.DATA_LIST, exportService.Export_fanxiu_bodysizes(category_id));
        return mv;
    }
    /**
     * 导出工艺类型
     */
    @RequestMapping(value = "/export_gongyi")
    public ModelAndView export_gongyi(String category_id) {
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, "工艺类型");
        //注解对象Class
        mv.addObject(NormalExcelConstants.CLASS, ExcelCategoryGongyi.class);
        //自定义表格参数
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("工艺类型", "工艺类型模板文件"));
        //导出数据列表
        mv.addObject(NormalExcelConstants.DATA_LIST, exportService.Export_all_gongyi(category_id));
        return mv;
    }

    /**
     * 导出撞色
     */
    @RequestMapping(value = "/export_zhuangse")
    public ModelAndView export_zhuangse(String category_id) {
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, "品类下撞色列表");
        //注解对象Class
        mv.addObject(NormalExcelConstants.CLASS, ExcelZhuangseInfo.class);
        //自定义表格参数
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("品类下撞色列表", "撞色模板文件"));
        //导出数据列表
        mv.addObject(NormalExcelConstants.DATA_LIST, exportService.Export_category_zhuangse(category_id));
        return mv;
    }


    /**
     * 导出袖子工艺
     */
    @RequestMapping(value = "/export_xiuzi")
    public ModelAndView export_xiuzi(String category_id,int type) {
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //type:1位置,2颜色，3图片，4字体，5高度
        if(type==1){
            //导出文件名称
            mv.addObject(NormalExcelConstants.FILE_NAME, "绣字工艺-刺绣部位");
            //注解对象Class
            mv.addObject(NormalExcelConstants.CLASS, ExcelXiuziLocaltion.class);
            //自定义表格参数
            mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("绣字工艺-刺绣部位", "刺绣部位模板文件"));
            //导出数据列表
            mv.addObject(NormalExcelConstants.DATA_LIST, exportService.Exportxiuzi_localtion(category_id));
        }else if(type==2){
            //导出文件名称
            mv.addObject(NormalExcelConstants.FILE_NAME, "绣字工艺-刺绣颜色");
            //注解对象Class
            mv.addObject(NormalExcelConstants.CLASS, ExcelXiuziColor.class);
            //自定义表格参数
            mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("绣字工艺-刺绣颜色", "刺绣颜色模板文件"));
            //导出数据列表
            mv.addObject(NormalExcelConstants.DATA_LIST, exportService.Exportxiuzi_color(category_id));
        }else if(type==3){
            //导出文件名称
            mv.addObject(NormalExcelConstants.FILE_NAME, "绣字工艺-刺绣图片");
            //注解对象Class
            mv.addObject(NormalExcelConstants.CLASS, ExcelXiuziFontImg2.class);
            //自定义表格参数
            mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("绣字工艺-刺绣图片", "刺绣图片模板文件"));
            //导出数据列表
            mv.addObject(NormalExcelConstants.DATA_LIST, exportService.Exportxiuzi_img(category_id));
        }else if(type==4){
            //导出文件名称
            mv.addObject(NormalExcelConstants.FILE_NAME, "绣字工艺-刺绣字体");
            //注解对象Class
            mv.addObject(NormalExcelConstants.CLASS, ExcelXiuziFontImg.class);
            //自定义表格参数
            mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("绣字工艺-刺绣字体", "刺绣字体模板文件"));
            //导出数据列表
            mv.addObject(NormalExcelConstants.DATA_LIST, exportService.Exportxiuzi_font(category_id));
        }else {
            //导出文件名称
            mv.addObject(NormalExcelConstants.FILE_NAME, "绣字工艺-绣字高度");
            //注解对象Class
            mv.addObject(NormalExcelConstants.CLASS, ExcelXiuziHeight.class);
            //自定义表格参数
            mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("绣字工艺-绣字高度", "绣字高度体模板文件"));
            //导出数据列表
            mv.addObject(NormalExcelConstants.DATA_LIST, exportService.Exportxiuzi_height(category_id));
        }
        return mv;
    }


    /**
     * 一键清空数据
     * @param
     * @param category_id 品类id
     */
    @PostMapping("/clean_all_categoryData")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject clean_all_categoryData(String category_id){
        JSONObject jsonObject = new JSONObject();
        System.out.println("传进来的==="+category_id);
        int result = exportService.clean_all_categorydata(category_id);
        if (result == 0) {
            jsonObject.put("code", 0);
            jsonObject.put("msg", "清空数据成功");
        }
        else {
            jsonObject.put("code", 1);
            jsonObject.put("msg", "清空失败");
        }
        return jsonObject;
    }

}
